package RuMen_Demo;

import java.util.*;

public class 抢红包 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Random r = new Random();
        System.out.println("请输入红包数目：");
        int n = sc.nextInt();
        float[] money = new float[n];
        int b = 0;
        System.out.println("请输入每个红包的金额：");
        for (int i = 0; i < n; i++) {
            money[i] = sc.nextFloat();
        }
        System.out.println("请输入你的用户名：");
        while (true) {
            if (b == n) {
                System.out.println("红包已抢完！");
                break;
            }
            int m = r.nextInt(n);
            if (money[m] != 0) {
                String name = sc.next();
                System.out.println("恭喜" + name + "抢到了" + money[m] + "\n");
                if (b < n - 1) System.out.println("请输入你的用户名：");
                money[m] = 0;
                b++;
            } else continue;
        }
    }
}
